<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h2>自定义组件的v-model</h2>
    <p>v-model实际上是input事件和名为value的props的结合</p>
    <main id="app">
        <my-component v-model="subText"></my-component>
        <p>子组件传来的值：{{subText}}</p>
    </main>
</body>
<script src="../vue.js"></script>
<script>
    Vue.component("my-component",{
        template: `<div>
            <input v-model="text">
            <button @click="handleClick">传值给父组件</button>
            <p>父组件传来的值: {{value}}</p>
        </div>`,
        props: ["value"],
        data() {
            return {
                text: ""
            }
        },
        methods: {
            handleClick() {
                this.$emit("input",this.text);
            }
        }
     })

    new Vue({
        el: "#app",
        data: {
            subText: "111",
        },
        methods: {
            // 获取p标签的dom对象
            handleInput(text) {
               this.subText = text;
            },
        }
    })
</script>
</html>